<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>企业微信登录失败</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .error-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.15);
            padding: 40px;
            width: 100%;
            max-width: 500px;
            text-align: center;
            animation: slideUp 0.5s ease-out;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .error-icon {
            font-size: 80px;
            margin-bottom: 20px;
            animation: bounce 2s infinite;
        }

        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% {
                transform: translateY(0);
            }
            40% {
                transform: translateY(-10px);
            }
            60% {
                transform: translateY(-5px);
            }
        }

        .error-title {
            font-size: 28px;
            font-weight: 700;
            color: #e74c3c;
            margin-bottom: 15px;
        }

        .error-subtitle {
            font-size: 18px;
            color: #666;
            margin-bottom: 25px;
            font-weight: 500;
        }

        .error-message {
            background: #fff5f5;
            border: 2px solid #fed7d7;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 30px;
            color: #c53030;
            font-size: 16px;
            line-height: 1.6;
            text-align: left;
        }

        .error-message strong {
            display: block;
            margin-bottom: 10px;
            font-size: 18px;
            color: #e53e3e;
        }

        .contact-info {
            background: #f7fafc;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 30px;
            text-align: left;
        }

        .contact-info h3 {
            color: #2d3748;
            margin-bottom: 15px;
            font-size: 18px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .contact-info p {
            color: #4a5568;
            margin-bottom: 8px;
            font-size: 14px;
            line-height: 1.5;
        }

        .action-buttons {
            display: flex;
            gap: 15px;
            justify-content: center;
            flex-wrap: wrap;
        }

        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background: #07C160;
            color: white;
        }

        .btn-primary:hover {
            background: #06AD56;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(7, 193, 96, 0.4);
        }

        .btn-secondary {
            background: #667eea;
            color: white;
        }

        .btn-secondary:hover {
            background: #5a6fd8;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }

        .btn-outline {
            background: transparent;
            color: #666;
            border: 2px solid #ddd;
        }

        .btn-outline:hover {
            background: #f8f9fa;
            border-color: #aaa;
        }

        .error-code {
            font-size: 12px;
            color: #999;
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }

        .wechat-logo {
            color: #07C160;
        }

        .admin-logo {
            color: #667eea;
        }

        /* 移动端适配 */
        @media (max-width: 480px) {
            .error-container {
                padding: 30px 20px;
            }

            .error-title {
                font-size: 24px;
            }

            .error-subtitle {
                font-size: 16px;
            }

            .action-buttons {
                flex-direction: column;
            }

            .btn {
                width: 100%;
                justify-content: center;
            }
        }

    </style>
</head>
<body>
<div class="error-container">
    <div class="error-icon">❌</div>
    <h1 class="error-title">企业微信登录失败</h1>
    <p class="error-subtitle">很抱歉，无法完成企业微信授权登录</p>

    <div class="error-message">
        <strong>错误信息：</strong>
        <span id="errorDetail">企业微信授权登录失败，请联系管理员。</span>
    </div>

    <div class="contact-info">
        <h3><span class="admin-logo">👨‍💼</span> 联系管理员</h3>
        <p>📧 如果问题持续存在，请联系系统管理员</p>
        <p>🔧 请提供以下信息以便快速解决问题：</p>
        <p>　• 登录时间：<span id="errorTime"></span></p>
        <p>　• 错误代码：<span id="errorCode">WX_LOGIN_ERROR</span></p>
        <p>　• 使用设备：<span id="userAgent"></span></p>
    </div>

    <div class="action-buttons">
        <button class="btn btn-primary" onclick="retryWeChatLogin()">
            <span class="wechat-logo">💬</span>
            重新尝试企业微信登录
        </button>
        <a class="btn btn-secondary" href="/evaluation/static/admin/login.html">
            <span class="admin-logo">🔐</span>
            使用其他方式登录
        </a>
        <button class="btn btn-outline" onclick="goBack()">
            <span>↩️</span>
            返回上一页
        </button>
    </div>

    <div class="error-code">
        错误时间：<span id="timestamp"></span> |
        系统版本：IVT绩效考核系统 v1.0.0
    </div>
</div>

<script>
        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', function() {
            initErrorPage();
        });

        function initErrorPage() {
            // 设置错误时间
            const now = new Date();
            const timeString = now.toLocaleString('zh-CN');
            document.getElementById('errorTime').textContent = timeString;
            document.getElementById('timestamp').textContent = timeString;

            // 设置用户代理信息
            const userAgent = navigator.userAgent;
            let deviceInfo = '未知设备';

            if (userAgent.includes('MicroMessenger')) {
                deviceInfo = '企业微信';
            } else if (userAgent.includes('Mobile')) {
                deviceInfo = '移动设备';
            } else {
                deviceInfo = '桌面浏览器';
            }

            document.getElementById('userAgent').textContent = deviceInfo;

            // 从URL参数获取错误信息
            const urlParams = new URLSearchParams(window.location.search);
            const error = urlParams.get('error');
            const code = urlParams.get('code');

            if (error) {
                document.getElementById('errorDetail').textContent = decodeURIComponent(error);
            }

            if (code) {
                document.getElementById('errorCode').textContent = code;
            }

            // 记录错误日志（可选）
            console.error('企业微信登录失败:', {
                error: error,
                code: code,
                time: timeString,
                userAgent: userAgent,
                url: window.location.href
            });
        }

        // 重新尝试企业微信登录
        function retryWeChatLogin() {
            // 清除URL参数，避免重复显示错误
            window.history.replaceState({}, document.title, window.location.pathname);

            // 跳转到企业微信登录
            window.location.href = '/evaluation/wechat/login';
        }

        // 返回上一页
        function goBack() {
            if (window.history.length > 1) {
                window.history.back();
            } else {
                window.location.href = '/evaluation/static/h5/index.html';
            }
        }

        // 复制错误信息到剪贴板
        function copyErrorInfo() {
            const errorInfo = `
企业微信登录错误信息：
错误详情：${document.getElementById('errorDetail').textContent}
错误代码：${document.getElementById('errorCode').textContent}
错误时间：${document.getElementById('errorTime').textContent}
使用设备：${document.getElementById('userAgent').textContent}
页面地址：${window.location.href}
            `.trim();

            if (navigator.clipboard) {
                navigator.clipboard.writeText(errorInfo).then(() => {
                    alert('错误信息已复制到剪贴板，请发送给管理员');
                }).catch(() => {
                    // 降级处理
                    fallbackCopyTextToClipboard(errorInfo);
                });
            } else {
                fallbackCopyTextToClipboard(errorInfo);
            }
        }

        // 降级复制方法
        function fallbackCopyTextToClipboard(text) {
            const textArea = document.createElement("textarea");
            textArea.value = text;
            textArea.style.position = "fixed";
            textArea.style.top = "-1000px";
            textArea.style.left = "-1000px";
            document.body.appendChild(textArea);
            textArea.focus();
            textArea.select();

            try {
                document.execCommand('copy');
                alert('错误信息已复制到剪贴板，请发送给管理员');
            } catch (err) {
                console.error('复制失败:', err);
                alert('复制失败，请手动复制错误信息');
            }

            document.body.removeChild(textArea);
        }

        // 添加复制按钮（可选）
        document.addEventListener('DOMContentLoaded', function() {
            const contactInfo = document.querySelector('.contact-info');
            const copyBtn = document.createElement('button');
            copyBtn.className = 'btn btn-outline';
            copyBtn.style.marginTop = '10px';
            copyBtn.style.width = '100%';
            copyBtn.innerHTML = '<span>📋</span> 复制错误信息';
            copyBtn.onclick = copyErrorInfo;
            contactInfo.appendChild(copyBtn);
        });

</script>
</body>
</html>
